from collections import deque

# 初始化双向队列
deque = deque()

deque.append(1)  # 添加至队尾
deque.append(5)
deque.append(4)
deque.appendleft(3)  # 添加至队首
deque.appendleft(2)

# 访问元素
front: int = deque[0]  # 队首元素
rear: int = deque[-1]  # 队尾元素

print(front, rear)

# 元素出队
pop_front: int = deque.popleft()  # 队首元素出队
pop_rear: int = deque.pop()  # 队尾元素出队

print(pop_front, pop_rear)

# 获取长度
length: int = len(deque)
print(length)

# 判断队列是否为空
is_empty: bool = len(deque) == 0
print(is_empty)
